package Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/AttributionServlet")
public class AttributionServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取选择的时间段参数
        String timeRange = request.getParameter("timeRange");

        // 执行归因分析（这里只是简单地模拟）
        String attributionResult = performAttributionAnalysis(timeRange);

        // 将结果存储在request属性中
        request.setAttribute("timeRange", timeRange);
        request.setAttribute("attributionResult", attributionResult);

        // 转发到结果页面
        request.getRequestDispatcher("attribution.jsp").forward(request, response);
    }

    private String performAttributionAnalysis(String timeRange) {
        // 这里执行实际的归因分析逻辑，这里只是一个示例
        // 实际情况下，你应该从数据库或其他数据源获取结果
        String result;
        switch (timeRange) {
            case "weekly":
                result = "这里是近一周的归因分析结果。";
                break;
            case "monthly":
                result = "这里是近一个月的归因分析结果。";
                break;
            case "yearly":
                result = "这里是近一年的归因分析结果。";
                break;
            default:
                result = "未选择时间段";
        }
        return result;
    }
}
